package com.snopy.concurrency.demo_base;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.*;

/**
 * @author
 * @description:进度条
 * @date 2020/9/2711:28
 */
public class Test2 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String [] arrs = new String[10];
        Random random = new Random(100);
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        Future<Map<String ,Object>> future = executorService.submit(() -> {

                StringBuilder jdt = new StringBuilder();
                String zd = "                                                                                                     ";
                for (int i = 0; i <= 100; i++) {

                        jdt.append("✌");
                        zd = zd.substring(1);


                    if (i%2==0){
                        arrs[0] = "加载进度" +"卍"+"【" +jdt+ zd  + "】"+ i + "%";
                    }else{
                        arrs[0] = "加载进度" +"卐"+"【" +jdt+ zd  + "】"+ i + "%";
                    }


                    System.out.print("\r" + arrs[0]);
                    TimeUnit.MILLISECONDS.sleep(random.nextInt(200));
                    TimeUnit.MILLISECONDS.sleep(random.nextInt(100));
                    TimeUnit.MILLISECONDS.sleep(random.nextInt(100));
                }
                Map<String, Object> map = new HashMap<>(1);
                map.put("result","游戏开始");
                return map;


        });
        Map<String, Object> objectMap = future.get();
        System.out.println();
        System.out.println(objectMap.get("result"));
        executorService.shutdown();
    }
}
